package cn.yunhe.exception;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import cn.yunhe.model.ResultModel;
import cn.yunhe.util.ErrorMessage;



/**
 * 全局的异常捕获
 * Created by Administrator on 2017/8/03.
 */

@RestControllerAdvice
public class GlobalExceptionHandler {
	
	Logger logger = LogManager.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public ResultModel<?> exceptionMsg001(Exception e){
        ResultModel<Void> rm = new ResultModel<Void>();
        rm.setCode(ErrorMessage.ERROR_SYSTEM_COMMON.code);
        rm.setMsg(ErrorMessage.ERROR_SYSTEM_COMMON.msg);
        logger.debug("logger执行");
        return rm;
    }
    
    @ExceptionHandler(ServiceException.class)
    public ResultModel<?> exceptionMsg201(ServiceException e){
        ResultModel<Void> rm = new ResultModel<Void>();
        rm.setCode(e.getErrorMsg().code);
        rm.setMsg(e.getErrorMsg().msg);
        return rm;
    }

}
